{extend name="public/base" /}
{block name='body'}
<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li><a href="login.html">登入</a></li>
                <li class="layui-this">找回密码</li>
            </ul>
            <div class="layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-pane">
                        <div class="layui-form">
                            <div class="layui-form-item">
                                <label for="email" class="layui-form-label">邮箱</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="email" name="email" required lay-verify="required"
                                          value="1228746736@qq.com" autocomplete="off" class="layui-input">
                                </div>
                                <button class="layui-btn layui-btn-danger" id="sw-send-email">发送验证码</button>
                            </div>
                            <div class="fly-msg">验证码10分钟内有效</div>
                            <div class="layui-form-item">
                                <label for="v_code" class="layui-form-label">验证码</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="v_code" name="code" required
                                           lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="pass" required
                                           lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_repass" class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_repass" name="repass" required
                                           lay-verify="required"
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-filter="reset" lay-submit>提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['jquery', 'layer', 'form'], function () {
        let layer = layui.layer, $ = layui.jquery, form = layui.form;

        //重置密码
        form.on('submit(reset)', function (obj) {
            let data = obj.field;
            if (data['pass'] !== data['repass']) {
                layer.alert('两次输入的密码不一致,请重试');
                return $("input[type='password']").val('');
            }
            $.post("{:url('login/resetApi')}", data, function (res) {
                if(res.errno===0){
                    layer.alert('密码重置成功',function () {
                        location.href= "{:url('login/login')}";
                    })
                }else{
                    layer.alert(err.errmsg);
                }
            })
        });

        //发送验证码到邮箱
        $('#sw-send-email').click(function () {
            let email = $('#email').val();
            let load= layer.load();
            $.get("{:url('login/resetMail')}?to=" + email, function (res) {
                layer.close(load);
                if (res.errno === 0) return layer.alert('验证码发送成功,请到邮箱查看');
                return layer.msg(res.errmsg);

            });
        })

    });
</script>
{/block}